﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ImageRecognition2.MouseImageTools
{
    /// <summary>
    /// This is creating the most important part. Events are send by the FormControl into
    /// activated tools.
    /// This class sends them on.
    /// Deriving from this class you'll have to always call the base to get the events.
    /// Example:
    /// 
    /// CCustomTool : CTool
    /// {
    ///   public override void OnMouseDown(object sender,MouseEventArgs e)
    ///   {
    ///      base.OnMouseDown(sender,e); //needs this!!!! otherwise you will get no event.
    ///   }
    /// }
    /// </summary>
    public class MouseImageTool : MouseImageToolBase
    {
        #region Declarations
        protected bool m_bLeftMouseDown = false;
        protected bool m_bRightMouseDown = false;
        protected bool m_bMiddleMouseDown = false;
        protected bool m_bXButton1Down = false;
        protected bool m_bXButton2Down = false;

        protected Point m_ptMouse = Point.Empty;
        #endregion Declarations

        #region Constructors

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_control"></param>
        public MouseImageTool(Control _control)
            : base(_control)
        {
        }
        #endregion Constructors

        #region Events
        /// <summary>
        /// Called when [mouse down].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        public override void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.m_bLeftMouseDown = (e.Button == MouseButtons.Left);
            this.m_bMiddleMouseDown = (e.Button == MouseButtons.Middle);
            this.m_bRightMouseDown = (e.Button == MouseButtons.Right);
            this.m_bXButton1Down = (e.Button == MouseButtons.XButton1);
            this.m_bXButton2Down = (e.Button == MouseButtons.XButton2);
        }

        /// <summary>
        /// Called when [mouse move].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        public override void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.m_ptMouse = e.Location;
        }

        /// <summary>
        /// Called when [mouse up].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        public override void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.m_bLeftMouseDown = !(e.Button == MouseButtons.Left);
            this.m_bMiddleMouseDown = !(e.Button == MouseButtons.Middle);
            this.m_bRightMouseDown = !(e.Button == MouseButtons.Right);
            this.m_bXButton1Down = !(e.Button == MouseButtons.XButton1);
            this.m_bXButton2Down = !(e.Button == MouseButtons.XButton2);
        }

        /// <summary>
        /// Called when [paint].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param>
        public override void OnPaint(object sender, PaintEventArgs e)
        {
            base.OnPaint(sender, e);
        }
        #endregion Events
    }
}
